package com.lunduhotel.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lunduhotel.dao.ClienteDao;
import com.lunduhotel.modelo.Cliente;

@WebServlet("/ServletAddCliente")
public class ServletAddCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public ServletAddCliente() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Cliente cliente = new Cliente();	
		cliente.setNome(request.getParameter("nomeCliente"));
		cliente.setIdade(Integer.parseInt(request.getParameter("idade")));
		cliente.setCpf(request.getParameter("cpf"));
		cliente.setEmail(request.getParameter("email"));
		cliente.setTelefone(request.getParameter("telefone"));
		ClienteDao clienteDao = new ClienteDao();
		clienteDao.adicionaCliente(cliente);
		request.setAttribute("msg", "Cliente adicionado com sucesso!");
		request.getRequestDispatcher("addCliente.jsp").forward(request, response);
	}

}
